Skip to content

Improve the output of the debugger#4365

Draft
jkyang92 wants to merge 14 commits into
Macaulay2:developmentfrom
jkyang92:debugger-output
Draft

Improve the output of the debugger#4365
jkyang92 wants to merge 14 commits into
Macaulay2:developmentfrom
jkyang92:debugger-output

Conversation

@jkyang92
Copy link
Copy Markdown
Contributor

This is a draft pull request improving the output of the current line of code in the debugger.

This pull request contains work with @adamlaclair @BrysonKagy @OlaPeteru from the Building the Future of Macaualy2 workshop. Comments welcome, I will still read through this to make sure that nothing is missing and no obvious issues remain.

These commits do not include any AI generated code.

@adamlaclair @BrysonKagy, Can you respond verifying that that the code from your commits can be distributed under GPL2+? (or the public domain or other compatible license if that is not acceptable)

@jkyang92 jkyang92 changed the title Debugger output Improve the output of the debugger May 24, 2026
Comment thread M2/Macaulay2/m2/code.m2
code Function := opt -> f -> codeFunction(null, f, 0)
code Command := opt -> C -> code C#0
code List := opt -> L -> DIV between_(HR{}) dedupMethods apply(L, code)
code ZZ := opt -> i -> code previousMethodsFound#i
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
code ZZ := opt -> i -> code previousMethodsFound#i
code ZZ := opt -> i -> code(previousMethodsFound#i, opt)

code(TestInput) in testing.m2 also needs updated to use options

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I'm afraid this is going to mess up code for hooks, e.g.:

i3 : code(syz, Matrix, Strategy => Default)

o3 = -- code for strategy: syz(Matrix,Strategy => Default)
     ../linuxbrew/.linuxbrew/Cellar/macaulay2/1.26.05/share/Macaulay2/Core/
     matrix2.m2:315:44-321:6: --source code:
     addHook((syz, Matrix), Strategy => Default, (opts, f) -> (
          if not isFreeModule target f or not isFreeModule source f
          then error "expected map between free modules";
          if ring f === ZZ or not isHomogeneous f
          then syz gb (f, opts, Syzygies=>true)
          else mingens image syz gb (f, opts, Syzygies=>true)
          ))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's going to be a hard issue to fix cleanly, given this issue, I'm leaning towards just using the global to control the formating. It's a bit unfortunate, because the downside of the new output is it's hard to copy paste.

Comment thread M2/Macaulay2/m2/code.m2


protect PrintCaret
protect PrintLineNum
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should export these, too, so users can pass them to code? If so, then I'd considering using PrintCarets and PrintLineNumbers to match the corresponding debug-prefixed global variables.

We'd also need to update the code docs accordingly.

Comment thread M2/Macaulay2/m2/test.m2
@@ -0,0 +1,29 @@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was adding this file just a git oopsie?

Comment thread M2/Macaulay2/m2/code.m2
file = lines file;
if #file < stop then error("line number ",toString stop, " not found in file ", filename);
DIV splice { codeAddress(x), codeContent(start, stop, file) }
DIV splice { codeAddress(x), codeContent(PrintCaret => debugPrintCarets, PrintLineNum => debugPrintLineNumbers, x, start, stop, file) }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we should use opt here. Maybe the default values should be null, and if so, use the global variables?

Either that or just drop options entirely and use the global variables inside codeContent?

@d-torrance d-torrance added Core Issues involving the Core scripts. Interpreter labels May 25, 2026
@BrysonKagy
Copy link
Copy Markdown

@jkyang92 Yes I am ok with the work being distributed under GPL2+

Comment on lines +87 to +92
-- ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, lastprompt = concatenate(interpreterDepth:"i", toString lineno, " : "));

ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, lastprompt = if (interpreterDepth == 1) then concatenate(interpreterDepth:"i", toString lineno, " : ") else concatenate("<M2 Debugger> ", interpreterDepth:"i", toString lineno, " : "));
-- if interpreterDepth > 0 then (
-- ZZ#{Standard,InputPrompt} = lineno -> concatenate("<M2 Debugger> ",lastprompt);
-- );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make the prompt a little shorter? Maybe just <debugger> iiNN : for instance?

Also the commented lines should be removed.

Suggested change
-- ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, lastprompt = concatenate(interpreterDepth:"i", toString lineno, " : "));
ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, lastprompt = if (interpreterDepth == 1) then concatenate(interpreterDepth:"i", toString lineno, " : ") else concatenate("<M2 Debugger> ", interpreterDepth:"i", toString lineno, " : "));
-- if interpreterDepth > 0 then (
-- ZZ#{Standard,InputPrompt} = lineno -> concatenate("<M2 Debugger> ",lastprompt);
-- );
ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline,
lastprompt = concatenate(if interpreterDepth == 1 then "<debugger> ", interpreterDepth:"i", toString lineno, " : ");

Comment thread M2/Macaulay2/d/interp.dd
oldDebuggerCode := getGlobalVariable(currentS);
setGlobalVariable(currentS,Expr(PseudocodeClosure(f,c)));
printMessage(codePosition(c), "entering debugger (enter 'help' to see commands)");
printMessage(codePosition(c), "\n"+ "ENTERING DEBUGGER (enter 'help' to see commands, enter 'break' to quit the debugger)");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make this print only once?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

I remember being surprised by this at the demo in Atlanta

"However, the following attempt results in an error, and the debugger starts up automatically.",
EXAMPLE "g 2",
"You may use ", TO "help", ", as instructed, to view the commands available in the debugger.
"Here it says ENTERING DEBUGGER when you enter the deugger. You may use ", TO "help", ", as instructed, to view the commands available in the debugger.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: deugger

@d-torrance d-torrance added the M2@GT26 Project from the "Future of Macaulay2" workshop at Georgia Tech in May 2026 label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core Issues involving the Core scripts. Interpreter M2@GT26 Project from the "Future of Macaulay2" workshop at Georgia Tech in May 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants